﻿<cfsilent>
	<cfscript>
		
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		markAdvice = getProperty("serviceFactory").getBean("markAdvice");

		classId = event.getArg("CLS");
		
		/* 班级信息 */
		sql = "SELECT cls_name FROM t_class WHERE cls_id = :classId ";
				
		queryObj = new Query( datasource=application.dnsSlave ) ;
   		queryObj.addParam( name="classId", value=classId, cfsqltype="cf_sql_char" );
		
		rs_class= queryObj.execute( sql=sql ).getResult();
		

		/* 学校信息 */
		sql = "SELECT sch_name FROM t_school a ";

		queryObj = new Query( datasource=application.dnsSlave ) ;

		rs_school= queryObj.execute( sql=sql ).getResult();

		
		event.setArg("pageTitle", "班级学生成绩证明 - " & rs_class.cls_name );
		
		passOnly = event.getArg("passOnly", 0);
		
		
		/* 默认显示行数及高度 */
		rowPerSlide = 42;
		rowPerPage = rowPerSlide * 2;
		
		/* 课程名最大长度 */
		maxChar = 16;
		
		/* Chrome Print Fix */
		if ( findNoCase( "Chrome", CGI.HTTP_USER_AGENT, 1) ) {
			maxChar = 14;
			rowPerSlide = 40;
			rowPerPage = rowPerSlide * 2;
		}

		/* 生成空记录 */
		rs_class_student = queryNew("stu_id");

		if ( len(classId) ) {

			sql = "SELECT stu_id FROM  t_student WHERE cls_id = :classId ";
						
			queryObj = new Query( datasource=application.dnsSlave ) ;
			queryObj.addParam( name="classId", value=classId, cfsqltype="cf_sql_char" );
			
			rs_class_student= queryObj.execute( sql=sql ).getResult();

		}
	
	</cfscript>
</cfsilent>

<style type="text/css">
@media print {
.UIprintable td { height:16px !important; }
}
</style>

<cfloop query="rs_class_student" >
	
	<cfif rs_class_student.currentRow gt 1><div class="page_break"></div></cfif>
	
	<cfscript>
		
		studentId = rs_class_student.stu_id;
		
		/* 学籍信息 */
		sql = "SELECT 
					a.stu_name, a.stu_id, a.stu_sex,b.cls_name, a.stu_birthday, a.stu_idcard, 
					c.level_code, c.sbj_name, 
					d.institute_name, 
					e.learning_branch, 
					f.credit_req_avgpt, f.credit_avgpt, f.credit, f.credit_req 
				FROM t_student a 
				INNER JOIN t_class b ON b.cls_id = a.cls_id 
				INNER JOIN t_subject c ON c.sbj_id = b.sbj_id 
				INNER JOIN t_institute d ON d.institute_id = c.institute_id 
				INNER JOIN t_learning_branch e ON e.b_id = c.b_id 
				INNER JOIN t_student_profile f ON f.stu_id = a.stu_id 
				WHERE 
					a.stu_id = :studentId ";
				
		queryObj = new Query( datasource=application.dnsSlave ) ;
   		queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
		
		rs_student = queryObj.execute( sql=sql ).getResult();
		
		
		/* 学生成绩数据 */
		if ( passOnly ) {
			
			sql = "SELECT 
						a.term_id, 
						b.course_name, b.course_credit, 
						a.retaking, a.mark_mode, 
						a.mark_result, a.mark_note,
						a.mark_resit, a.mark_renote, a.mark_resit_limit, 
						c.prop_name, c.prop_id 
					FROM t_student_mark a 
						 INNER JOIN t_course b ON b.cid = a.cid 
						 INNER JOIN t_course_prop c ON c.prop_id = a.prop_id 
					WHERE 
						  a.stu_id = :stuId 
						  AND 
						  (
							a.mark_result >= 60 OR a.mark_resit >= 60
						  )
					ORDER BY a.term_id, c.prop_name, b.course_name ";
					
			queryObj = new Query( datasource=application.dnsSlave ) ;
			queryObj.addParam( name="stuId", value=studentId, cfsqltype="cf_sql_varchar" );
			
			rs_mark = queryObj.execute( sql=sql ).getResult();
			
		} 
		else {
			
			sql = "SELECT 
						a.term_id, 
						b.course_name, b.course_credit, 
						a.retaking, a.mark_mode, 
						a.mark_result, a.mark_note,
						a.mark_resit, a.mark_renote, a.mark_resit_limit, 
						c.prop_name, c.prop_id 
					FROM t_student_mark a 
						 INNER JOIN t_course b ON b.cid = a.cid 
						 INNER JOIN t_course_prop c ON c.prop_id = a.prop_id 
					WHERE 
						  a.stu_id = :stuId 
					ORDER BY a.term_id, c.prop_name, b.course_name ";
					
			queryObj = new Query( datasource=application.dnsSlave ) ;
			queryObj.addParam( name="stuId", value=studentId, cfsqltype="cf_sql_varchar" );
			
			rs_mark = queryObj.execute( sql=sql ).getResult();
		}
		
		if ( rs_mark.recordCount ) {
			
			/* 计算打印页数 */
			if ( rs_mark.recordCount mod rowPerPage ) {
				totlePageCount = int(rs_mark.recordCount/rowPerPage) + 1;
			}
			else {
				totlePageCount = int(rs_mark.recordCount/rowPerPage);
			}
			
			pageRowBegin = 1;
			pageRowEnd = min(rowPerPage, rs_mark.recordCount);
			
			tagCode = "CJP-" & rs_student.stu_id;

		}
		
	</cfscript>

	<cfif rs_mark.recordCount>

		<!--- 分页打印单个学生成绩单 --->
		<cfloop from="1" to="#totlePageCount#" index="currentPage">
	
			<cfif currentPage GT 1><div class="page_break"></div></cfif>
			<div class="UIreportTitle"><h2><cfoutput>#rs_school.sch_name#</cfoutput> <cfoutput>#rs_student.stu_name#</cfoutput> 成绩单</h2></div>
	
			<table class="UIprintable">
				<tr height="30">
					<td>学号</td>
					<td><cfoutput>#rs_student.stu_id#</cfoutput></td>
					<td>姓名</td>
					<td><cfoutput>#rs_student.stu_name#</cfoutput></td>
					<td>性别</td>
					<td><cfif rs_student.stu_sex eq "1">男<cfelse>女</cfif></td>
					<td>班级</td>
					<td><cfoutput>#rs_student.cls_name#</cfoutput></td>
					<td rowspan="4" width="90"><img width="90" height="120" align="middle" src="<cfoutput>#getContextRoot()#</cfoutput>/acadmicManager/student/print/<cfoutput>#rs_student.stu_id#</cfoutput>.jpg" /></td>
				</tr>
				<tr height="30">
					<td>出生日期</td>
					<td><cfoutput>#datetimeAdvice.formatDateString(rs_student.stu_birthday)#</cfoutput></td>
					<td>身份证</td>
					<td colspan="3"><cfoutput>#rs_student.stu_idcard#</cfoutput></td>
					<td>学历层次</td>
					<td><cfoutput>#dictAdvice.getStudentLevel(rs_student.level_code)#</cfoutput></td>
				</tr>
				<tr height="30">
					<td>专业</td>
					<td><cfoutput>#rs_student.sbj_name#</cfoutput></td>
					<td>学院</td>
					<td colspan="3"><cfoutput>#rs_student.institute_name#</cfoutput></td>
					<td>课程绩点</td>
					<td><cfoutput>#numberFormat(rs_student.credit_avgpt, "_.___")#</cfoutput></td>
				</tr>
				<tr height="30">
					<td>学科类别</td>
					<td><cfoutput>#rs_student.learning_branch#</cfoutput></td>
					<td>学分</td>
					<td><cfoutput>#numberFormat(rs_student.credit, "_.__")#</cfoutput></td>
					<td>必修课学分</td>
					<td><cfoutput>#numberFormat(rs_student.credit_req, "_.__")#</cfoutput></td>
					<td>必修课绩点</td>
					<td><cfoutput>#numberFormat(rs_student.credit_req_avgpt, "_.___")#</cfoutput></td>
				</tr>
			</table>
	
			<div class="clear2px"></div>
	
			<table width="100%" cellpadding="0" cellspacing="0">
				<tr>
					<td valign="top" width="50%">
						<!-- Silder Left -->
						<table class="UIprintable" width="100%" border="1" cellpadding="0" cellspacing="0">
							<tr>
								<td>课程名称</td>
								<td width="35">成绩</td>
								<td width="30">学分</td>
								<td width="30">类别</td>
								<td width="30">学期</td>
							</tr>
							<cfset sliderRowBegin = pageRowBegin />
							<cfset sliderRowEnd = pageRowBegin + rowPerSlide -1 />
							<cfloop index="row" from="#sliderRowBegin#" to="#sliderRowEnd#">
						
								<cfif rs_mark.recordCount gte row >
									<cfset markFinal = markAdvice.getMarkResult( rs_mark["mark_mode"][row], rs_mark["mark_result"][row], rs_mark["mark_note"][row], rs_mark["mark_resit"][row], rs_mark["mark_renote"][row], rs_mark["mark_resit_limit"][row] ) />
									<tr>
										<td class="left"><cfoutput>#left(rs_mark["course_name"][row], maxChar)#</cfoutput></td>
										<td><cfoutput>#markFinal#</cfoutput></td>
										<td><cfoutput>#numberFormat(rs_mark["course_credit"][row], "_.__")#</cfoutput></td>
										<td><cfoutput>#rs_mark["prop_name"][row]#</cfoutput></td>
										<td><cfoutput>#rs_mark["term_id"][row]#</cfoutput></td>
									</tr>
									<cfelse>
									<tr>
										<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
									</tr>
								</cfif>
						
							</cfloop>
						</table>
					</td>
					<td width="5" valign="top">&nbsp;</td>
					<td valign="top" width="50%">
						<!-- Silder Right -->
						<table class="UIprintable" width="100%" border="1" cellpadding="0" cellspacing="0">
							<tr>
								<td>课程名称</td>
								<td width="35">成绩</td>
								<td width="30">学分</td>
								<td width="30">类别</td>
								<td width="30">学期</td>
							</tr>
							<cfset sliderRowBegin = pageRowBegin + rowPerSlide />
							<cfset sliderRowEnd = pageRowBegin + 2*rowPerSlide -1 />
							<cfloop index="row" from="#sliderRowBegin#" to="#sliderRowEnd#">
						
								<cfif rs_mark.recordCount gte row >
									<cfset markFinal = markAdvice.getMarkResult( rs_mark["mark_mode"][row], rs_mark["mark_result"][row], rs_mark["mark_note"][row], rs_mark["mark_resit"][row], rs_mark["mark_renote"][row], rs_mark["mark_resit_limit"][row] ) />
									<tr>
										<td class="left"><cfoutput>#left(rs_mark["course_name"][row], maxChar)#</cfoutput></td>
										<td><cfoutput>#markFinal#</cfoutput></td>
										<td><cfoutput>#numberFormat(rs_mark["course_credit"][row], "_.__")#</cfoutput></td>
										<td><cfoutput>#rs_mark["prop_name"][row]#</cfoutput></td>
										<td><cfoutput>#rs_mark["term_id"][row]#</cfoutput></td>
									</tr>
									<cfelse>
									<tr>
										<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
									</tr>
								</cfif>
						
							</cfloop>
						</table>
					</td>
				</tr>
			</table>
	
			<div class="UIreportFoot">
				<table>
					<tr>
						<td>打印时间 <cfoutput>#dateFormat(now(), "YYYY年MM月DD日")#</cfoutput></td>
						<td><cfoutput>#rs_school.sch_name#</cfoutput> （签章有效）</td>
						<td>第 <cfoutput>#currentPage#</cfoutput> 页, 共 <cfoutput>#totlePageCount#</cfoutput> 页</td>
						<td align="right"><img src="<cfoutput>#getContextRoot()#</cfoutput>/barcode/Print/<cfoutput>#tagCode#</cfoutput>.png" height="43"/></td>
					</tr>
				</table>
			</div>
	
			<cfset pageRowBegin = pageRowBegin + rowPerPage />
			<cfset pageRowEnd = pageRowEnd + rowPerPage />
			<cfif pageRowEnd gt rs_mark.recordCount>
				<cfset pageRowEnd = rs_mark.recordCount />
			</cfif>
	
		</cfloop>
		
		
	</cfif>

	<!-- /studentMark -->

</cfloop>